package cn.luow.freemarker.starter;

import cn.luow.freemarker.service.FreemarkerMagicDynamicRegistry;
import cn.luow.freemarker.service.FtlInfoMagicResourceStorage;
import cn.luow.freemarker.service.ResponseFunctionExtension;
import cn.luow.freemarker.web.MagicFreemarkerController;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.ssssssss.magicapi.core.config.MagicPluginConfiguration;
import org.ssssssss.magicapi.core.model.Plugin;
import org.ssssssss.magicapi.core.web.MagicControllerRegister;

public class MagicAPIFreemarkerConfiguration implements MagicPluginConfiguration {
    @Override
    public Plugin plugin() {
        return new Plugin("freemarker", "MagicFreemarker","magic-freemarker.1.0.0.iife.js");
    }

    @Override
    public MagicControllerRegister controllerRegister() {
        return (mapping, configuration) -> mapping.registerController(new MagicFreemarkerController(configuration));
    }
    @Bean
    @ConditionalOnMissingBean
    public FtlInfoMagicResourceStorage ftlInfoMagicResourceStorage() {
        return new FtlInfoMagicResourceStorage();
    }
    @Bean
    @ConditionalOnMissingBean
    public FreemarkerMagicDynamicRegistry freemarkerMagicDynamicRegistry(FtlInfoMagicResourceStorage ftlInfoMagicResourceStorage) {

        return new FreemarkerMagicDynamicRegistry(ftlInfoMagicResourceStorage);
    }
    @Bean
    public ResponseFunctionExtension responseFunctionExtension() {

        return new ResponseFunctionExtension();
    }
}
